home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 3 / Amethyst.iso / live / usr / lib / rpm-3.0.6 / mkcopyright.pl < prev    next >
Encoding:
Perl Script  |  2000-06-06  |  2.1 KB  |  92 lines

  1. #!/usr/bin/perl -w
  2. # $Id: mkcopyright.pl,v 1.1 1997/11/20 01:15:59 ray Exp ray $
  3. #use strict;
  4.  
  5. ($C = $0) =~ s%.*/%%;
  6.  
  7. my $In;
  8. my $Out;
  9. my $Mode = 1;
  10.  
  11. my $Help = 0;
  12. my $OptErr = "";
  13. my $verbose = 0;
  14. my $debug = 0;
  15. my $p = 0;
  16.  
  17.  
  18. sub cpmod($$) {
  19.   my( $Org, $Dup) = @_;
  20.   my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  21.       $atime,$mtime,$ctime,$blksize,$blocks) = stat($Org);
  22.   $mode &= 007777; $mode |= 000200;
  23.   chown( $uid, $gid, $Dup) || die( "$CMD: cannot chown( $uid, $gid, $Dup).\n");
  24.   chmod( $mode, $Dup) || die( "$CMD: cannot chmod( $mode, $Dup).\n");
  25.   utime( $atime, $mtime, $Dup) || die( "$CMD: cannot utime( $Dup).\n");
  26. }
  27.  
  28.  
  29. while ( $#ARGV >= $[ && ($_ = shift, /^-/ || (unshift(@ARGV,$_) && 0)) ) {
  30.   last if /^--$/;
  31.   (/^--mode=(\d+)$/)            && ($Mode = $1, next);
  32.   (/^--verbose$/ || /^-v$/)        && ($verbose ++, next);
  33.   (/^--debug$/ || /^-d$/)        && ($debug ++, $verbose ++, next);
  34.   (/^--?help/ || /^-h/)            && ($Help = 1, next);
  35.   (/^-/)                && ($OptErr .= "$_ ", $_ = "", next);
  36. }
  37.  
  38.  
  39. $OptErr = sprintf( "$C: unkown option: %s\n", $OptErr) if ( $OptErr );
  40.  
  41. if ( $#ARGV < $[ + 1 ) {
  42.   $OptErr .= sprintf( "$C: missing parameter(s)\n");
  43. } elsif ( $#ARGV > $[ + 1 ) {
  44.   $OptErr .= sprintf( "$C: superfluous parameter(s)\n");
  45. } else {
  46.   $In = shift;
  47.   $Out = shift;
  48. }
  49.  
  50. if ( $OptErr || $Help ) {
  51.   print( STDERR $OptErr) if ( $OptErr );
  52.   die( "Usage: $C [options] in out\n");
  53. }
  54.  
  55. open( IN, "<$In") || die("open($In): $!\n");
  56. open( OUT, ">$Out") || die("open($Out): $!\n");
  57. select( OUT);
  58.  
  59. if ( $Mode == 1 ) {
  60.   print( " *\n");
  61.  
  62.   while ( <IN> ) {
  63.     $p = 1 if ( /^ \* Copy/ );
  64.     $p = 1 if ( /^ \* THIS/ );
  65.     last if ( /^ \*\// );
  66.     print if ( $p );
  67.     $last = $_;
  68.   }
  69.  
  70.   print( " *\n") unless ( $last =~ /^ \*\s*$/ );
  71. } elsif ( $Mode == 2 ) {
  72.   print( " *\n");
  73.  
  74.   while ( <IN> ) {
  75.     $p = 1 if ( /^ \* THIS/ );
  76.     last if ( /^ \*\// );
  77.     print if ( $p );
  78.     $last = $_;
  79.   }
  80.  
  81.   print( " *\n") unless ( $last =~ /^ \*\s*$/ );
  82. } else {
  83.   unlink $Out;
  84.   print( STDERR "$C: mode $Mode not implemented!\n");
  85.   exit( 1);
  86. }
  87.  
  88. close( OUT);
  89. close( IN);
  90. cpmod( $In, $Out) unless ( $Out eq "-" );
  91. exit( 0);
  92.